#include "./main.h"
#include <stdio.h>

void imx6ul_hardfpu_enable(void);

/**
 * @brief main函数
 *
 * @return int
 */
int main(void) {

  imx6ul_hardfpu_enable(); /* 使能I.MX6U的硬件NEON和FPU */
  int_init();              /* 初始化中断(一定要最先调用！) */
  imx6u_clkinit();         /* 初始化系统时钟 			*/
  clk_enable();            /* 使能所有的时钟 			*/
  led_init();              /* 初始化led 			*/

  lcd_init();
  /* 初始化触摸屏					*/
  gt9147_init();
  if (gt_init_fail == 1) // 判断gt系列初始化是否失败
  {
    printf("gt系列初始化失败 \r\n");
  }

  camera_init();

  unsigned char id[2];

  camera_read_id(id);

  while (1) {
    printf("H %x L %x \r\n", id[1], id[0]);
    delay_s(1);
  }

  return 0;
}

#if 0

    tftlcd_dev.forecolor = LCD_RED;
    lcd_show_string(50, 40, 400, 32, 32, (char *)"TP Num	:");
    lcd_show_string(50, 80, 200, 32, 32, (char *)"Point0 X:");
    lcd_show_string(50, 120, 200, 32, 32, (char *)"Point0 Y:");
    lcd_show_string(50, 160, 200, 32, 32, (char *)"Point1 X:");
    lcd_show_string(50, 200, 200, 32, 32, (char *)"Point1 Y:");
    lcd_show_string(50, 240, 200, 32, 32, (char *)"Point2 X:");
    lcd_show_string(50, 280, 200, 32, 32, (char *)"Point2 Y:");
    lcd_show_string(50, 320, 200, 32, 32, (char *)"Point3 X:");
    lcd_show_string(50, 360, 200, 32, 32, (char *)"Point3 Y:");
    lcd_show_string(50, 400, 200, 32, 32, (char *)"Point4 X:");
    lcd_show_string(50, 440, 200, 32, 32, (char *)"Point4 Y:");
    tftlcd_dev.forecolor = LCD_BLUE;
    lcd_shownum(50 + 150, 40, gt9147_dev.point_num, 1, 32);
    lcd_shownum(50 + 150, 80, gt9147_dev.x[0], 5, 32);
    lcd_shownum(50 + 150, 120, gt9147_dev.y[0], 5, 32);
    lcd_shownum(50 + 150, 160, gt9147_dev.x[1], 5, 32);
    lcd_shownum(50 + 150, 200, gt9147_dev.y[1], 5, 32);
    lcd_shownum(50 + 150, 240, gt9147_dev.x[2], 5, 32);
    lcd_shownum(50 + 150, 280, gt9147_dev.y[2], 5, 32);
    lcd_shownum(50 + 150, 320, gt9147_dev.x[3], 5, 32);
    lcd_shownum(50 + 150, 360, gt9147_dev.y[3], 5, 32);
    lcd_shownum(50 + 150, 400, gt9147_dev.x[4], 5, 32);
    lcd_shownum(50 + 150, 440, gt9147_dev.y[4], 5, 32);

#endif

/*
 * @description	: 使能I.MX6U的硬件NEON和FPU
 * @param 		: 无
 * @return 		: 无
 */
void imx6ul_hardfpu_enable(void) {
  uint32_t cpacr;
  uint32_t fpexc;

  /* 使能NEON和FPU */
  cpacr = __get_CPACR();
  cpacr = (cpacr & ~(CPACR_ASEDIS_Msk | CPACR_D32DIS_Msk)) |
          (3UL << CPACR_cp10_Pos) | (3UL << CPACR_cp11_Pos);
  __set_CPACR(cpacr);
  fpexc = __get_FPEXC();
  fpexc |= 0x40000000UL;
  __set_FPEXC(fpexc);
}